package com.mmy.dao.oa;

import java.util.List;

import javax.transaction.Transactional;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import com.mmy.domain.oa.LeaveType;

public interface LeaveTypeRepository extends JpaRepository<LeaveType, Integer> {

	/*
	 * 获取最大值id
	 */
	@Query(value = "select MAX(iTypeID) from tSysLeaveType", nativeQuery = true)
	Object getMaxTypeID();

	/*
	 * 根据name查找
	 */
	@Query(value = "select *  from tSysLeaveType where cTypeName like %:strTypeName%", nativeQuery = true)
	List<LeaveType> findByTypeName(@Param("strTypeName") String strTypeName);

	/*
	 * 根据id删除
	 */
	@Transactional
	@Modifying
	@Query(value = "delete from tSysLeaveType where tSysLeaveType.iTypeID in (:lstTypeID)", nativeQuery = true)
	void delLeaveType(@Param("lstTypeID") List<Integer> lstTypeID);

	/*
	 * 根据id查找
	 */
	@Query(value = "select *  from tSysLeaveType where iTypeID = :iTypeID", nativeQuery = true)
	LeaveType findByTypeID(@Param("iTypeID") int iTypeID);


	/*
	 * 新增id
	 */
	@Transactional
	@Modifying
	@Query(value = "INSERT INTO tSysLeaveType(iTypeID, cTypeName, fPayment, dCreateDate, cCreator, dModifyDate, cReviser, cMemo, cSpare1, cSpare2, cSpare3, cSpare4, cSpare5) VALUES (:typeID, NULL, 0, NULL, NULL, NULL, NULL, '', NULL, NULL, NULL, NULL, NULL)", nativeQuery = true)
	void save(@Param("typeID") int typeID);

}
